import pandas as pd
import pymysql


# 自定义函数连接数据库获取数据
def connFun():
    conn = pymysql.connect(host="localhost"
                           , user="root"
                           , password="200028"
                           , port=3306
                           , db="dataView")
    sql = "select * from night"
    data = pd.read_sql(sql, conn)
    return data


# 自定义函数求各城市的平均间夜数
def analysisFun():
    value = connFun()
    value['Night'] = value['Night'].astype("float")
    df = value.groupby("City", as_index=False)['Night'].mean()
    city = df.City.tolist()
    night = df.Night.tolist()
    return city, night
